#ifndef __SWTIMER_H
#define __SWTIMER_H
#include "config.h"

#define 	SWTimer_EnterCritical()		__disable_irq()
#define		SWTimer_ExitCritical()		__enable_irq()

//链表节点
typedef struct SWTimer_t
{
  struct SWTimer_t* Next;
  struct SWTimer_t* Pre;

  //需要延时的时间
  uint32_t DelayTimes;
  //时基
  uint32_t TicksCounter;
  //超时回调函数
  void (*timerout_cb)(void);
  //链表拥有者
  void* ListOwner;
}SWTimer_t;

//链表首节点
typedef struct MiniNode_t
{
  SWTimer_t* Next;
  SWTimer_t* Pre;
}SWTimerMiniNode_t;


typedef struct List_t
{
  //软件定时器计数器
  uint32_t SWTimerCounter;
  //链表首节点
  SWTimerMiniNode_t FirstNode;
}SWTimerList_t;


void SWTimer_Init(void);
void SWTimer_Start(SWTimer_t* SWTimerHandle,uint32_t DelayTicks,void (*TimerOut_CB)(void));
void SWTimer_Stop(SWTimer_t* SWTimerHandle);
void SWTimer_Tick(void);
void SWTimer_TimeOutProcess(void);
uint8_t SWTimer_ISStart(SWTimer_t* SWTimerHandle);
#endif



